/**
 *
 * Ori Weisler  ID 060512878
 * Rony Lahav   ID 043489889 
 * Date: Jun 24, 2009
 */

public class Table{
	public int curLocation;	//current location in symbol table
	public String varName;	//i
	public String varType;	//var/const/type
	public int varData=-1;		//int / pointer to next symbol table
	public int varMem=-1;		//pointer to memory / const value
	public int nextSymTable=-1;//pointer to next symbol table
	
	public void print(){
		System.out.println("*****symbol at location " + curLocation + "*****");
		if (varName.equals("NIL")){
			System.out.println("NIL");
			return;
		}
		if (!varName.startsWith("#"))		//name starts with # for array and struct
			System.out.println(varName);
		System.out.println(varType);		//type always full
		if (varData<0){						//for struct
			System.out.println(nextSymTable);
			return;
		}
		if (varData == 1002)				//1002=int else address of array/type 
			System.out.println("int");
		else
			System.out.println(varData);
		if (varMem>=0)						//if -1 then const or type, else memory
			System.out.println(varMem);
		else
			System.out.println("-");
		if (!varName.startsWith("#")){					//for array name starts with # (so nothing to print), else next symbol or null
			if (nextSymTable>=0)	//<0 for type int chain
				System.out.println(nextSymTable);
			else
				System.out.println("NIL");
		}
		
	}
	
	public Table copy(){
		Table newT = new Table();
		newT.curLocation=this.curLocation;
		newT.nextSymTable=this.nextSymTable;
		newT.varData=this.varData;
		newT.varMem=this.varMem;
		newT.varName=this.varName;
		newT.varType=this.varType;
		return newT;
	}
}